<template>
  <div>
    <van-search
      v-model="searchValue"
      placeholder="请输入政策名"
      shape="round"
      @search="onSearch"
      @cancel="onCancel"
    />
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <zw-list
        @goToPolicyDetail="goToPolicyDetail"
        v-for="(item,index) in listData"
        :key="index"
        pageName="policyDocument"
        :configData="item"
      ></zw-list>
    </van-list>
  </div>
</template>

<script>
export default {
  data() {
    return {
      searchValue: "",
      listData: [],
      loading: false,
      finished: false,
      queryData: {
        pageSize: 10,
        pageNo: 1,
        jsdx: JSON.parse(sessionStorage.getItem("userData")).id,
      },
    };
  },
  created() {},
  methods: {
    getList() {
      this.$api
        .policyReview({ method: "post", type: "datagrid" }, this.queryData)
        .then((res) => {
          this.listData.push(...res.data.data);
          if (this.listData.length == res.data.total)
            return (this.finished = true);
          this.queryData.pageNo++;
          this.loading = false;
        });
    },
    onLoad() {
      this.getList();
    },
    onSearch() {
      this.queryData.pageNo = 1;
      this.queryData.name = this.searchValue;
      this.finished = false
      this.loading = true
      this.listData = []
      this.onLoad()
    },
    onCancel() {},
    // 跳转到政策详情并标记为已读
    goToPolicyDetail(policyBaseId, id) {
      this.$api.policyReview(
        { method: "post", type: "save" },
        {
          policyBaseId,
          id,
          isRead: 2,
          jsdx: JSON.parse(sessionStorage.getItem("userData")).id,
        }
      );
      this.$router.push({ name: "policyDetail", params: { id } });
    },
  },
};
</script>

<style scoped lang="less">
</style>
